package com.dhecp.project.storage.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.core.layui.GridColumnsPropertyModel;
import com.dhecp.project.common.controller.BaseModuleController;
import com.dhecp.project.storage.domain.GaugeMaintenance;
import com.dhecp.project.storage.service.GaugeMaintenanceService;

/**
 * @program: kjecp
 * @description: 货位管理 控制层
 * @author: hlf
 * @create: 2022-09-08 14:32
 */
@Controller
@RequestMapping("/storage/gaugeMaintenance")
public class GaugeMaintenanceController extends BaseModuleController {

    private String prefix = "storage/gaugeMaintenance";
    private String moduleTable = ModuleTable.GAUGE_MAINTENANCE;

    @Autowired
    private GaugeMaintenanceService storageService;
    @Autowired
    private GridColumnsPropertyModel gridColumnsPropertyModel;

    /**
     *打开选择页面
     */
    @GetMapping("/select")
    public ModelAndView select(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        params.put("entity", new GaugeMaintenance()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("toolBarWidth", 0);
        if(params.get("pagetype") !=null && params.get("pagetype").toString().equalsIgnoreCase("checkbox"))params.put("checkBox", "yes");
        else params.put("radio", "yes");
        ModelAndView mv = this.getModelAndView();
        AjaxResult ajaxResult = new AjaxResult();
        Map<String, Object> dictionaryForFieldMap = new HashMap<String, Object>();

        mv.addObject("fields", TypeUtils.mapToJson(dictionaryForFieldMap));
        mv.addObject("ajaxResult", ajaxResult);
        mv.addObject("gridColumns", gridColumnsPropertyModel.queryGridColumnsPropertyModel(params));
        mv.addObject("prefix", prefix);
        mv.addObject("moduleTable", moduleTable);
        mv.setViewName("common/select");
        return mv;
    }


    /**
     * @Description: 列表数据
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        List<GaugeMaintenance> list = new ArrayList<GaugeMaintenance>();
        try {
            list = storageService.queryList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }
}